package com.framework.service.yhbservice.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.YHBDao.transactionDao.YhbBenefitDayDao;
import com.framework.page.PageUtils;
import com.framework.service.yhbservice.YhbBenefitDayService;
import com.framework.yhbEntity.transaction.YhbBenefitDay;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Transactional(rollbackFor = Exception.class)
@Service("yhbBenefitDayService")
public class YhbBenefitDayServiceImpl extends ServiceImpl<YhbBenefitDayDao,YhbBenefitDay> implements YhbBenefitDayService {

    @Override
    public PageUtils queryBenfitPage(Map<String, Object> params) {


        params.put("startTime", params.get("startTime")==null||"".equals(params.get("startTime").toString())?null:params.get("startTime"));
        params.put("endTime", params.get("endTime")==null||"".equals(params.get("endTime").toString())?null:params.get("endTime"));
        Integer currpage = Integer.valueOf(params.get("page").toString());
        Integer pageSize = Integer.valueOf(params.get("limit").toString());
        params.put("start", (currpage - 1) * pageSize);
        params.put("limit", pageSize);
        List<Map<String,Object>> list=baseMapper.queryBenefitlist(params);
        Integer count=baseMapper.queryBenefitCount(params);
        return new PageUtils(list, count, pageSize, currpage);
    }

    @Override
    public PageUtils queryDetailByBenefitId(Map<String, Object> params) {
        Integer pageSize=Integer.valueOf(params.get("limit").toString());
        Integer currPage=Integer.valueOf(params.get("page").toString());
        params.put("start",(currPage-1)*pageSize);
        params.put("limit",pageSize);
        List<Map<String,Object>> list=this.baseMapper.queryDetailByBenefitId(params);
        Integer totalCount=this.baseMapper.queryCountByBenefitId(params);

        return new PageUtils(list,totalCount,pageSize,currPage);
    }
}
